//
//  ViewController.m
//  18-SQLite
//
//  Created by 鹏飞罗 on 16/8/8.
//  Copyright © 2016年 罗鹏飞. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManager.h"
#import "Student.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *openSQLite;
@property (weak, nonatomic) IBOutlet UIButton *closeSQLite;
@property (nonatomic, strong) SQLiteDataBaseManager *dataBaseManager;
@end

@implementation ViewController

- (IBAction)openSQLite:(id)sender {
    [_dataBaseManager openSQLite3];
}

- (IBAction)closeSQLite:(id)sender {
    [_dataBaseManager closeSQLite3];
}

- (IBAction)createTable:(id)sender {
    [_dataBaseManager cerateTable];
}
- (IBAction)insertStu:(id)sender {
    Student *stu = [[Student alloc] init];
    stu.stu_id = 38;
    stu.stu_name = @"XX";
    [_dataBaseManager insertStu:stu];
}
- (IBAction)deleteStu:(id)sender {
    
//    Student *stu = [[Student alloc] init];
//    stu.stu_id = 38;
//    [_dataBaseManager deleteStu:stu];
    [_dataBaseManager deleteAll];
}
- (IBAction)updateName:(id)sender {
    [_dataBaseManager updateOldName:@"XX" newName:@"王道林"];
}
- (IBAction)selectAll:(id)sender {
    NSArray *array = [_dataBaseManager selectAll];
    NSLog(@"%ld",array.count);
    NSLog(@"%@",[array description]);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _dataBaseManager = [SQLiteDataBaseManager sharedManager];
   // SQLite3
   // 注意：使用SQLite需要引入 libsql3.0.tbd
//  libsqlite3.0.tbd 和 libsqlite3.tbd 区别
//    libsqlite3.0.tbd 是 libsqlite3.tbd 的替身文件， 防止用户误删
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
